import React, { useState } from 'react';
import { Button, Form, Input, Select, Space } from 'antd';
import axios from 'axios'
import md5 from 'md5'
const layout = {
    labelCol: { span: 8 },
    wrapperCol: { span: 16 },
};

const tailLayout = {
    wrapperCol: { offset: 8, span: 16 },
};
const Index = () => {

    let [title, settitle] = useState('三部分')

    const [form] = Form.useForm();
    const onFinish = (values: any) => {
        settitle(values.note)
        console.log(title);
        // let salt = new Date().getTime()
        // console.log(salt);
        var appKey = '195b31806c86150b';
        var key = 'R9XWO96UF7dX65wYVFmmQhGrmq8lcbsy';//注意：暴露appSecret，有被盗用造成损失的风险
        var salt = (new Date).getTime();
        var curtime = Math.round(new Date().getTime() / 1000);
        var query = '您好欢迎再次使用有道智云文本翻译API接口服务';
        // 多个query可以用\n连接  如 query='apple\norange\nbanana\npear'
        var to = 'en';
        var str1 = appKey + query + salt + curtime + key;
        var sign = md5(str1)
        axios.get('/apis', {
            params: {
                q: query,
                from: 'auto',
                to,
                appKey,
                curtime,
                salt,
                sign,
            }
        }).then(res => {
            console.log(res);
        })
    };

    return (
        <div>
            <Form
                {...layout}
                form={form}
                name="control-hooks"
                onFinish={onFinish}
                style={{ maxWidth: 600 }}
            >
                <Form.Item name="note" label="Note">
                    <Input />
                </Form.Item>

                <Form.Item name="gender" label="Gender" >
                    <Select
                        allowClear
                        placeholder="转换语言"
                        options={[
                            { label: 'en', value: 'en' },
                            { label: 'ja', value: 'ja' },
                            { label: '	th', value: '	th' },
                        ]}
                    />
                </Form.Item>

                <Form.Item {...tailLayout}>
                    <Space>
                        <Button type="primary" htmlType="submit">
                            有道翻译
                        </Button>


                    </Space>
                </Form.Item>
            </Form>
        </div>
    )
}

export default Index
